package com.rr.service.impl;

import com.rr.entity.Users;
import com.rr.dao.UsersDao;
import com.rr.service.UsersService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * (Users)表服务实现类
 *
 * @author makejava
 * @since 2025-06-01 14:56:18
 */
@Service("usersService")
public class UsersServiceImpl implements UsersService {
    @Resource
    private UsersDao usersDao;

    /**
     * 通过ID查询单条数据
     *
     * @param userid 主键
     * @return 实例对象
     */
    @Override
    public Users queryById(Integer userid) {
        return this.usersDao.queryById(userid);
    }

    /**
     * 动态查询所有用户
     * @param users
     * @return
     */
    @Override
    public List<Users> queryAllUsers(Users users) {
        return usersDao.queryAllByLimit(users);
    }




    /**
     * 新增数据
     *
     * @param users 实例对象
     * @return 实例对象
     */
    @Override
    public Users insert(Users users) {
        this.usersDao.insert(users);
        return users;
    }

    /**
     * 修改数据
     *
     * @param users 实例对象
     * @return 实例对象
     */
    @Override
    public Users update(Users users) {
        this.usersDao.update(users);
        return this.queryById(users.getUserid());
    }

    /**
     * 通过主键删除数据
     *
     * @param userid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer userid) {
        return this.usersDao.deleteById(userid) > 0;
    }
    /**
     * 登录校验密码
     */
    @Override
    public Users login(String username, String password) {
        Users users = usersDao.queryByUsername(username);

         System.out.println(users);
         if (users != null && users.getUserPassword().equals(password)) {

             users.setUserPassword(null);
            return users;
        }
        return null;
    }
}
